<template>
  <Header/>
  <div class="resume">
    <div class="header"> 
      <div class="info">
        <!-- 介绍 -->
        <div class="introduce">
          <div class="row1">I am <span class="name" >Airs</span></div>
          <div class="row1">一名小白开发工程师</div>
          <div class="row2">一直想成为一个开发工程师，不管路途有多艰辛我都希望自己可以一直走下去，所谓“路虽远，行则将至，事虽难，作则必成”，为了梦想不断努力！<span class="encourage-text">诸君共勉</span>
          </div>
        </div>
        <!-- 头像 -->
        <div class="avatar">
            <img :src="developerImage" alt="developer">
          </div>
        </div>
    </div>

    <!-- 我的技术栈 -->
    <div class="technology">
      <div class="tech-container-wrapper">
        <div class="tech-stack-with-title" ref="techStackRef" :class="{ 'visible': isTechVisible }">
          <div class="title">我的技术栈</div>
          <div class="circle-container">
        <img 
          v-for="(item, index) in technology" 
          :key="item.name"
          :src="getIcon(item.name)"
          :alt="item.name"
          :style="{
            backgroundColor: item.background,
            '--x': `${getCirclePosition(index).x}px`,
            '--y': `${getCirclePosition(index).y}px`,
            transform: `translate(${getCirclePosition(index).x}px, ${getCirclePosition(index).y}px)`
          }"
          class="tech-icon"
        >
        <!-- 中心内容 -->
        <div class="circle-center">
          <div class="center-title">小白开发</div>
          <div class="center-subtitle">熟悉13+技术</div>
        </div>
        </div>
        </div>
        
        <!-- 年度目标 -->
        <div class="yearly-goals" ref="yearlyGoalsRef" :class="{ 'visible': isGoalsVisible }">
          <div class="title">年度目标</div>
          <div class="goals-list">
            <div class="goal-item" :ref="el => el && goalItemsRef.push(el)">
              <div class="goal-icon"></div>
              <div class="goal-content">
                <div class="goal-name">1.找到一个  java后端开发 的实习工作 </div>
                <div class="goal-progress">
                  <div class="progress-bar">
                    <div class="progress-fill" style="width: 0%"></div>
                  </div>
                  <div class="progress-text">0%</div>
                </div>
              </div>
            </div>
            <div class="goal-item" :ref="el => el && goalItemsRef.push(el)">
              <div class="goal-icon"></div>
              <div class="goal-content">
                <div class="goal-name">2.掌握 Redis 高级特性</div>
                <div class="goal-progress">
                  <div class="progress-bar">
                    <div class="progress-fill" style="width: 50%"></div>
                  </div>
                  <div class="progress-text">50%</div>
                </div>
              </div>
            </div>
            <div class="goal-item" :ref="el => el && goalItemsRef.push(el)">
              <div class="goal-icon"></div>
              <div class="goal-content">
                <div class="goal-name">3.学习 Java 的微服务</div>
                <div class="goal-progress">
                  <div class="progress-bar">
                    <div class="progress-fill" style="width: 0%"></div>
                  </div>
                  <div class="progress-text">0%</div>
                </div>
              </div>
            </div>
            <div class="goal-item" :ref="el => el && goalItemsRef.push(el)">
              <div class="goal-icon" ></div>
              <div class="goal-content">
                <div class="goal-name">4.让自己的个人博客网站上线</div>
                <div class="goal-progress">
                  <div class="progress-bar">
                    <div class="progress-fill" style="width: 60%"></div>
                  </div>
                  <div class="progress-text">55%</div>
                </div>
              </div>
            </div>
            <div class="goal-item" :ref="el => el && goalItemsRef.push(el)">
              <div class="goal-icon"></div>
              <div class="goal-content">
                <div class="goal-name">5.深入学习 AI 应用开发</div>
                <div class="goal-progress">
                  <div class="progress-bar">
                    <div class="progress-fill" style="width: 30%"></div>
                  </div>
                  <div class="progress-text">30%</div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

</template>

<script setup>
import Header from '@/layouts/components/Header.vue'
import { useStore } from 'vuex'
import { onMounted, onUnmounted, computed, ref } from 'vue'

// 导入头像图片
import developerImage from '@/assets/developer.png'

// 导入所有SVG图标
import HTMLIcon from '@/assets/icon/HTML.svg'
import CSSIcon from '@/assets/icon/CSS.svg'
import JavaScriptIcon from '@/assets/icon/JavaScript.svg'
import TypeScriptIcon from '@/assets/icon/TypeScript.svg'
import VueIcon from '@/assets/icon/Vue.svg'
import ViteIcon from '@/assets/icon/Vite.svg'
import PiniaIcon from '@/assets/icon/Pinia.svg'
import WebpackIcon from '@/assets/icon/Webpack.svg'
import MySQLIcon from '@/assets/icon/MySQL.svg'
import MiniAppIcon from '@/assets/icon/小程序.svg'
import GitHubIcon from '@/assets/icon/GitHub.svg'
import AiIcon from '@/assets/icon/Ai.svg'
import DwIcon from '@/assets/icon/Dw.svg'
import HarmonyIcon from '@/assets/icon/harmony.svg'
import DefaultIcon from '@/assets/weblog-logo-mini.png'

const store = useStore()

// 动画相关的引用
const techStackRef = ref(null)
const yearlyGoalsRef = ref(null)
const goalItemsRef = ref([])
const isTechVisible = ref(false)
const isGoalsVisible = ref(false)

// 保存observer引用，以便在组件卸载时清理
let techObserver = null
let goalsObserver = null


// 创建技术栈名称到图标路径的映射表
const iconMap = {
  'HTML': HTMLIcon,
  'CSS': CSSIcon,
  'JavaScript': JavaScriptIcon,
  'TypeScript': TypeScriptIcon,
  'Vue': VueIcon,
  'Vite': ViteIcon,
  'Pinia': PiniaIcon,
  'Webpack': WebpackIcon,
  'MySQL': MySQLIcon,
  '小程序': MiniAppIcon,
  'GitHub': GitHubIcon,
  'Ai': AiIcon,
  'Dw': DwIcon,
  'harmony': HarmonyIcon
}

// 动态获取图片路径
const getIcon = (icon) => {
  const iconPath = iconMap[icon];
  if (!iconPath) {
    console.warn(`图标 ${icon} 未找到`);
    return DefaultIcon;
  }
  return iconPath;
}

// 滚动检测逻辑
onMounted(() => {
  // 技术栈的观察者
  techObserver = new IntersectionObserver(
    (entries) => {
      entries.forEach(entry => {
        if (entry.isIntersecting) {
          // 使用一个小延迟来确保动画能够正确重置和重放
          setTimeout(() => {
            isTechVisible.value = true
          }, 100)
        } else {
          // 当元素离开视口时重置状态，以便下次进入时再次触发动画
          isTechVisible.value = false
        }
      })
    },
    { threshold: 0.1 }
  )
  
  // 年度目标的观察者
  goalsObserver = new IntersectionObserver(
    (entries) => {
      entries.forEach(entry => {
        if (entry.isIntersecting) {
          // 清空之前的引用
          goalItemsRef.value = []
          // 使用一个小延迟来确保动画能够正确重置和重放
          setTimeout(() => {
            isGoalsVisible.value = true
            // 为每个目标项添加动画类
            setTimeout(() => {
              if (goalItemsRef.value.length > 0) {
                goalItemsRef.value.forEach((item, index) => {
                  if (item) {
                    // 先移除可能存在的动画类
                    item.classList.remove('animate')
                    // 强制重排
                    void item.offsetWidth
                    // 添加动画类以触发动画
                    item.classList.add('animate')
                  }
                })
              }
            }, 100)
          }, 100)
        } else {
          // 当元素离开视口时重置状态，以便下次进入时再次触发动画
          isGoalsVisible.value = false
          // 移除所有目标项的动画类
          if (goalItemsRef.value.length > 0) {
            goalItemsRef.value.forEach((item) => {
              if (item) {
                item.classList.remove('animate')
              }
            })
          }
        }
      })
    },
    { threshold: 0.1 }
  )
  
  if (techStackRef.value) {
    techObserver.observe(techStackRef.value)
  }
  
  if (yearlyGoalsRef.value) {
    goalsObserver.observe(yearlyGoalsRef.value)
  }
})

  // 在组件卸载时清理observer
  onUnmounted(() => {
    if (techObserver) {
      techObserver.disconnect()
    }
    if (goalsObserver) {
      goalsObserver.disconnect()
    }
  })

  // 技术栈列表
  const technology = [
  {
    name: "HTML",
    background: "#f74916"
  },
  {
    name: "CSS",
    background: "#3e95f1"
  },
  {
    name: "JavaScript",
    background: "#fbcb34"
  },
  {
    name: "TypeScript",
    background: "#007acc"
  },
  {
    name: "Vue",
    background: "#4fc08d"
  },
  {
    name: "Vite",
    background: "#977bf5"
  },
  {
    name: "Pinia",
    background: "#dea584"
  },
  {
    name: "Webpack",
    background: "#8dd6f9"
  },
  {
    name: "MySQL",
    background: "#4479a1"
  },
  {
    name: "小程序",
    background: "#b9f0af"
  },
  {
    name: "GitHub",
    background: "#181717"
  },
  {
    name: "Ai",
    background: "#251301"
  },
  {
    name: "Dw",
    background: "#082601"
  },
  {
    name: "harmony",
    background: "#ff6b6b"
  },
]


// 计算圆形位置函数
const getCirclePosition = (index) => {
  const radius = 226; // 圆的半径
  const totalItems = technology.length;
  // 计算角度，从0开始，均匀分布在圆周上
  const angle = (index / totalItems) * 2 * Math.PI;
  // 计算x和y坐标，中心点偏移
  const x = Math.cos(angle) * radius;
  const y = Math.sin(angle) * radius;
  return { x, y };
}
</script>

<style scoped lang="scss">
$move: 0.3s;
$textColor: var(--theme-text);
$borderColor: var(--theme-border);
$w: 1200px;

.resume {
  margin-top: 60px;
  background-color: var(--theme-background);
  transition: background-color $move;

  .header {
      position: relative;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
      min-height: 600px;
      background-color: var(--theme-background);
      background-size: 100%;
      z-index: 15;
      padding: 40px 0;

      .info {
        max-width: $w;
        width: 100%;
        display: flex;
        align-items: center;
        padding: 0 20px;
        background-color: var(--theme-background);

        .introduce {
          order: 1; /* 确保在左边 */
          width: 450px;
          margin-right: 100px;
          color: var(--theme-text);
          font-family: LongZhuTi;
          transition: all 0.8s;
     
          .name {
            color: #ff739f;
          }

          .row {
            font-size: 60px;
            margin-top: 70px;
          }

          .row1 {
            color: $textColor;
            font-size: 40px;
            margin: 40px 0 30px;
            transition: color $move;
          }

          .row2 {
          color: var(--theme-text-secondary);
          font-family: "黑体";
          line-height: 30px;
          transition: color $move;
        }

        .encourage-text {
          font-weight: bold;
          font-size: 22px;
          color: #738bff;
          margin-left: 5px;
        }
        }

        .avatar {
          order: 2; /* 确保在右边 */
          overflow: hidden;
          width: 400px;
          height: 400px;
          border-radius: 50%;
          box-shadow: rgba(149, 157, 165, 0.2) 0px 8px 24px;

          img {
            width: 100%;
            height: 100%;
          }
        }
      }
    }

  .technology {
    min-height: 600px;
    background-color: var(--theme-background);
    transition: background-color $move;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 0;

    .tech-stack-with-title {
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    
    .title {
      color: $textColor;
      font-weight: 900;
      padding-top: 15px;
      padding-bottom: 30px;
      text-align: center;
      font-family: kuaikan;
      transition: color $move;
      font-size: 28px;
    }

    .tech-container-wrapper {
      display: flex;
      align-items: flex-start;
      justify-content: center;
      gap: 60px;
      width: 100%;
      max-width: 1300px;
      margin: 0 auto;
      padding: 0 20px;
    }
    
    .circle-container {
      position: relative;
      width: 600px;
      height: 600px;
      flex-shrink: 0;
      animation: rotate 30s linear infinite;

      .tech-icon {
        position: absolute;
        top: 50%;
        left: 50%;
        width: 70px;
        height: 70px;
        padding: 15px;
        margin: -45px 0 0 -45px; /* 居中偏移 */
        border-radius: 20px;
        border: 1px solid $borderColor;
        box-shadow: 0 2px 16px -3px rgba(0, 0, 0, 0.15);
        transition: all 0.3s ease;
        animation: rotateReverse 30s linear infinite;
        z-index: 2;

        &:hover {
          transform: translate(calc(var(--x) * 0.9px), calc(var(--y) * 0.9px)) scale(1.2);
          z-index: 3;
        }
      }

      .circle-center {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 200px;
        height: 200px;
        background-color: var(--theme-card-bg);
        border-radius: 50%;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
        z-index: 1;

        .center-title {
          font-size: 24px;
          font-weight: bold;
          color: var(--theme-text);
          margin-bottom: 10px;
        }

        .center-subtitle {
          font-size: 16px;
          color: var(--theme-text-secondary);
        }
      }
    }

    // 悬停暂停整个动画
    .technology:hover .circle-container {
      animation-play-state: paused;
    }

    .technology:hover .tech-icon {
      animation-play-state: paused;
    }
    
    // 年度目标样式
    .yearly-goals {
      width: 600px;
      height: 600px;
      padding: 0;
      background: none;
      border: none;
      box-shadow: none;
      flex-shrink: 0;
      display: flex;
      flex-direction: column;
      align-items: center;
    }
    
    
    
    .goals-list {
      display: flex;
      flex-direction: column;
      gap: 20px;
      height: 100%;
      justify-content: space-between;
      padding: 30px 0;
    }
    
    .goal-item {
      display: flex;
      align-items: flex-start;
      gap: 20px;
      padding: 10px 0;
    }
    
    .goal-icon {
      font-size: 40px;
      width: 60px;
      height: 60px;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-shrink: 0;
    }
    
    .goal-content {
      flex: 1;
    }
    
    .goal-name {
      color: var(--theme-text);
      font-size: 20px;
      font-weight: bold;
      margin-bottom: 12px;
    }
    
    .goal-progress {
      display: flex;
      align-items: center;
      gap: 15px;
    }
    
    .progress-bar {
      flex: 1;
      height: 12px;
      background-color: var(--theme-background-soft);
      border-radius: 6px;
      overflow: hidden;
    }
    
    .progress-fill {
      height: 100%;
      background: linear-gradient(90deg, #738bff, #5a67d8);
      border-radius: 6px;
      transition: width 1s ease;
    }
    
    .progress-text {
      color: var(--theme-text-secondary);
      font-size: 18px;
      min-width: 60px;
      text-align: right;
    }
  }
  
  // 移动端响应式设计
  @media (max-width: 1024px) {
    .header {
      min-height: auto !important;
      height: auto !important;
    }
    
    .header .info {
      flex-direction: column;
      padding: 20px;
    }
    
    .header .introduce {
      order: 2 !important;
      width: 100% !important;
      margin-right: 0 !important;
      text-align: center;
    }
    
    .header .row1 {
      font-size: 32px !important;
      margin: 20px 0 15px !important;
    }
    
    .header .row2 {
      font-size: 16px;
      line-height: 24px;
    }
    
    .header .avatar {
      order: 1 !important;
      width: 250px !important;
      height: 250px !important;
      margin-bottom: 30px;
    }
    
    .tech-container-wrapper {
      flex-direction: column !important;
      gap: 40px !important;
    }
    
    .circle-container {
      width: 400px !important;
      height: 400px !important;
    }
    
    .circle-container .tech-icon {
      width: 50px !important;
      height: 50px !important;
      padding: 10px !important;
      margin: -35px 0 0 -35px !important;
    }
    
    .circle-center {
      width: 150px !important;
      height: 150px !important;
    }
    
    .circle-center .center-title {
      font-size: 20px !important;
    }
    
    .circle-center .center-subtitle {
      font-size: 14px !important;
    }
    
    .yearly-goals {
      width: 100% !important;
      height: auto !important;
    }
    
    .goals-list {
      padding: 0px !important;
    }
    
    .goal-item {
      padding: 15px !important;
      background-color: var(--theme-card-bg);
      border-radius: 10px;
      box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
    }
    
    .goal-name {
      font-size: 18px !important;
    }
    
    .progress-text {
      font-size: 16px !important;
    }
  }



  // 圆形旋转动画
  @keyframes rotate {
    from {
      transform: rotate(0deg);
    }
    to {
      transform: rotate(360deg);
    }
  }

  // 反向旋转以保持图标正面朝上
  @keyframes rotateReverse {
    from {
      transform: translate(var(--x), var(--y)) rotate(360deg);
    }
    to {
      transform: translate(var(--x), var(--y)) rotate(0deg);
    }
  }
  
  // 入场动画 - 技术栈
  @keyframes techEntry {
    from {
      opacity: 0;
      transform: translateX(-50px) scale(0.9);
    }
    to {
      opacity: 1;
      transform: translateX(0) scale(1);
    }
  }
  
  // 入场动画 - 年度目标
  @keyframes goalsEntry {
    from {
      opacity: 0;
      transform: translateX(50px) scale(0.9);
    }
    to {
      opacity: 1;
      transform: translateX(0) scale(1);
    }
  }
  
  // 动画应用
  .tech-stack-with-title {
    opacity: 0;
    transform: translateX(-50px) scale(0.9);
  }
  
  .tech-stack-with-title.visible {
    animation: techEntry 0.8s ease-out forwards;
  }
  
  .yearly-goals {
    opacity: 0;
    transform: translateX(50px) scale(0.9);
  }
  
  .yearly-goals.visible {
    animation: goalsEntry 0.8s ease-out 0.2s forwards;
  }
  
  // 为年度目标的每个item添加渐入效果
  .goal-item {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.5s ease, transform 0.5s ease;
  }
  
  .goal-item.animate {
    animation: goalItemEntry 0.5s ease-out forwards;
  }
  
  .goal-item.animate:nth-child(1) {
    animation-delay: 0.4s;
  }
  
  .goal-item.animate:nth-child(2) {
    animation-delay: 0.6s;
  }
  
  .goal-item.animate:nth-child(3) {
    animation-delay: 0.8s;
  }
  
  .goal-item.animate:nth-child(4) {
    animation-delay: 1.0s;
  }
  
  .goal-item.animate:nth-child(5) {
    animation-delay: 1.2s;
  }
  
  // 目标项的入场动画
  @keyframes goalItemEntry {
    from {
      opacity: 0;
      transform: translateY(20px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

}
</style>